package com.bw.zonghe0719.utils

import android.content.Context
import android.widget.ImageView
import androidx.databinding.BindingAdapter
import com.bumptech.glide.Glide
import com.youth.banner.Banner
import com.youth.banner.loader.ImageLoader

object LoadImage {
    /**
     * 封装绑定适配器    bindingAdapter
     * 实现在 xml文件中引入网络图片
     */
    @JvmStatic
    @BindingAdapter("img_url")
    fun loadPic(imageView: ImageView,url:String?){
        if(url!=null){
            Glide.with(imageView.context).load(url).into(imageView)
        }
    }
    /**
     * 显示轮播图
     */
    @JvmStatic
    @BindingAdapter("banner_url")
    fun loadBanner(banner: Banner,list:MutableList<String>?){
        if(list!=null){
            if(list.isNotEmpty()){
                banner.setImages(list)
                    .setImageLoader(object :ImageLoader(){
                        override fun displayImage(
                            context: Context?,
                            path: Any?,
                            imageView: ImageView?
                        ) {
                            if(context!=null&&path!=null&&imageView!=null){
                                Glide.with(context).load(path).into(imageView)
                            }
                        }

                    }).start()
            }
        }
    }
}